<template>
	<view>
		<view class="px-3 pt-3" style="padding-bottom: 180rpx;">
			<view class="bt-block">
				<bg-cell2 required label="姓名" :value="$store.getters.name"></bg-cell2>
				<bg-cell2 label="性别">
					<template slot="value">
						<bg-label :options="dict.type.sys_user_sex" :value="$store.state.user.gender"></bg-label>
					</template>
				</bg-cell2>
				<bg-cell2 label="身份证" :value="$store.getters.idCard"></bg-cell2>
				<bg-cell2 label="联系方式" :border="false" :value="$store.state.user.phone"></bg-cell2>
			</view>

			<view class="bt-block mt-3 p-2">
				<u--form labelWidth="80" errorType="toast" :labelStyle="{ fontSize: '28rpx' }" labelPosition="left"
					:model="postData" :rules="postData.workPost == 1 ? rules : rules2" ref="uForm">
					<u-form-item labelWidth="168" labelPosition="top" required label="手持身份证照片" prop="handledIdCardUrl">
					</u-form-item>
					<view class="mb-3">
						<bg-upload key="handledIdCardUrl" :value.sync="postData.handledIdCardUrl"
							:count="1"></bg-upload>
					</view>
					<view class="bt-line-1"> </view>
					<u-form-item labelPosition="left" required label="工作岗位" prop="workPost">
						<view class="form-block">
							<bg-select :value.sync="postData.workPost" :columns="dict.type.work_post"
								key="workPost"></bg-select>
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item v-if="postData.workPost == 1" labelPosition="left" required label="工种"
						prop="workJobType">
						<view class="form-block">
							<bg-select :value.sync="postData.workJobType" :columns="workJobs"
								key="workJobType"></bg-select>
						</view>
					</u-form-item>
					<view class="bt-line-1" v-if="postData.workPost == 1"> </view>
					<u-form-item labelPosition="left" required label="入职项目" prop="projectId">
						<view class="form-block">
							<bg-select :value.sync="postData.projectId" :columns="projectList"
								key="project"></bg-select>
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item labelPosition="left" required label="用工期限">
						<!-- <u-form-item labelPosition="left" required label="用工期限" prop="workDeadline"> -->
						<view class="form-block">
							<u-input inputAlign='right' placeholder="完成约定的任务期限为用工期限" disabled disabledColor="#fff"
								border="none">
							</u-input>
							<!-- <u-input inputAlign='right' type="number" border="none" v-model="postData.workDeadline">
								<template slot="suffix">
									<text>天</text>
								</template>
							</u-input> -->
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item labelPosition="left" required label="报酬方式" prop="salaryType">
						<view class="form-block">
							<bg-select :value.sync="postData.salaryType" :columns="salaryTypes"
								key="gender"></bg-select>
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item v-if="postData.salaryType == 1" labelPosition="left" required label="日薪"
						prop="daySalaryAmount">
						<view class="form-block">
							<u--input inputAlign='right' type="number" border="none" v-model="postData.daySalaryAmount">

							</u--input>
						</view>
					</u-form-item>
					<u-form-item v-else-if="postData.salaryType == 2" labelPosition="left" required label="月薪"
						prop="monthSalaryAmount">
						<view class="form-block">
							<u--input inputAlign='right' type="number" border="none"
								v-model="postData.monthSalaryAmount">
							</u--input>
						</view>
					</u-form-item>
					<u-form-item v-else-if="postData.salaryType == 3" labelPosition="left" required label="计量报酬"
						prop="meteringAmount">
						<view class="form-block flex align-center">
							<view class="mr-1">
								<u--input style="max-width: 220rpx;" inputAlign='right' border="none"
									placeholder="请输入计量报酬" v-model="postData.meteringAmount">
								</u--input>
							</view>
							<bg-select :value.sync="postData.meteringUnit" :columns="dict.type.unit_type"
								key="unitType"></bg-select>
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item labelPosition="left" label="发薪日期" prop="payDay">
						<view class="form-block">
							每月15日
						</view>
					</u-form-item>
					<view class="bt-line-1"> </view>
					<u-form-item labelPosition="left" label="合同类别" prop="contractType">
						<view class="form-block">
							临时用工合同
						</view>
					</u-form-item>

				</u--form>
			</view>
			<view class="bt-block my-3">
				<bg-title class="margin-top mx-3">
					<text class="font-1">流程节点图</text>
				</bg-title>
				<view class="p-3">
					<bg-step :list="authList"></bg-step>
				</view>
			</view>
			<view class="" style="height: 200rpx;"></view>
		</view>
		<view class="bt-footer">
			<bg-btn @tap="saveData">提交</bg-btn>
		</view>
		<bg-confirm content="请确认信息填报正确？一经保存将生成劳动合同" @confirm="confirmModal" @close="closeModal"
			:show.sync="show"></bg-confirm>
	</view>

</template>

<script>
import {
	getDictShow
} from "@/utils/common.js"
import {
	salaryTypes
} from "@/utils/constant.js"
import { addEntry, editEntry, getWorkTypeList, getEntry } from "@/api/entry.js"
import { getProject } from "../../../api/project"
import { onLoad } from "../../../uni_modules/uview-ui/libs/mixin/mixin"
export default {
	dicts: ["sys_user_sex", "emergency_type", "work_post", "unit_type"],
	mounted() {
		this.$store.dispatch("types/getJobs").then(res => {
			this.workJobs = res
		})
		// this.$store.dispatch("types/getProjects").then(res=>{
		// 	this.projectList = res
		// })
		this.getProjectList()
	},
	data() {
		return {
			ch: false,
			show: false,
			workJobs: [],
			projectList: [],
			salaryTypes: salaryTypes,
			postData: {
				"userId": this.$store.getters.userId,
				"projectId": '',
				"handledIdCardUrl": "",
				"workPost": "",
				"workJobType": '',
				// "workDeadline": '',
				"salaryType": "",
				"daySalaryAmount": '',
				"monthSalaryAmount": '',
				"meteringAmount": '',
				"meteringUnit": "",
				"payDay": "",
				"contractType": ""
			},
			rules: {
				handledIdCardUrl: [{
					required: true,
					message: "请上传身份证照片"
				}],
				workPost: [{
					required: true,
					message: "请选择工作岗位"
				}],
				workJobType: [{
					required: true,
					message: "请选择工种"
				}],
				projectId: [{
					required: true,
					message: "请选择入职项目"
				}],
				salaryType: [{
					required: true,
					message: "请选择报酬方式"
				}],
				handledIdCardUrl: [{
					required: true,
					message: "请上传身份证照片"
				}],
			},
			rules2: {
				handledIdCardUrl: [{
					required: true,
					message: "请上传身份证照片"
				}],

				workPost: [{
					required: true,
					message: "请选择工作岗位"
				}],
				projectId: [{
					required: true,
					message: "请选择入职项目"
				}],
				salaryType: [{
					required: true,
					message: "请选择报酬方式"
				}],
				handledIdCardUrl: [{
					required: true,
					message: "请上传身份证照片"
				}],
			},
			workTypeList: [],
			id: '',
			authList: [],

		}
	},
	computed: {

	},
	onLoad(options) {
		if (options.id) {
			this.id = options.id
			this.getData()
		}
	},
	methods: {
		getProjectList() {
			getProject({ pageNum: 1, pageSize: 100 }).then(res => {
				let _data = res.data.rows
				_data.forEach(d => {
					d.label = d.projectName
					d.value = d.id
				})
				this.projectList = _data

			})
		},
		getData() {
			getEntry(this.id).then(res => {
				this.postData = {
					...res.data,
				}

				this.authList = [{
					auditUserName: res.data.realName,
					auditTime: res.data.createTime
				},
				...res.data.auditRecordList
				]
			})
		},
		closeModal() {
			this.show = false;
		},
		confirmModal() {
			// 新增 有id 修改 二次提交

			// if (this.id) {
			// 	this.postData.id = this.id
			// 	editEntry(this.postData).then(res => {
			// 		console.log('this.postData----------', this.postData);
			// 		console.log('addEntry(this.postData)', res);
			// 		uni.$emit("refresh-enter", this.postData.projectId)
			// 		uni.$emit("refresh-user", true)
			// 		this.$modal.msg("提交成功")
			// 		this.$tab.navigateBackDelay()
			// 	})
			// } else {
			// console.log('this.postData----------', this.postData);

			// return
			addEntry(this.postData).then(res => {
				console.log('this.postData----------', this.postData);
				console.log('addEntry(this.postData)', res);
				uni.$emit("refresh-enter", this.postData.projectId)
				uni.$emit("refresh-user", true)
				this.$modal.msg("提交成功")
				// this.$tab.navigateBackDelay()
				uni.navigateBack({})
			})
			// }



		},
		saveData() {
			this.$refs.uForm.validate().then(res => {
				if (res) {
					this.show = true;
				}
			})
		},

	}
}
</script>

<style></style>